﻿using System.Windows.Controls;
using SnakeGame.ViewModels;
using System.Windows.Input;

namespace SnakeGame.Views
{
    /// <summary>
    /// Interaction logic for QuestionPage.xaml
    /// </summary>
    public partial class QuestionPage : Page
    {
        private QuestionPageViewModel _questionPageViewModel;
        private QuestionFrame _frame;

        public QuestionPage()
        {
            InitializeComponent();
            //this.PreviewKeyDown += StartButton_PreviewKeyDown;
        }

        public void Initialize(QuestionFrame questionFrame)
        {
            _frame = questionFrame;
            _questionPageViewModel = new QuestionPageViewModel();

            DataContext = _questionPageViewModel;
            _questionPageViewModel.Initialize(questionFrame);
        }

        private void StartButton_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                _questionPageViewModel.StartCommand.Execute(sender);
            }
        }

        private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            _frame.Window.KeyDown += StartButton_PreviewKeyDown;
        }


    }
}
